/**
 * 
 */
package nc.tb.pub.ui;

import java.awt.Component;
import java.awt.Graphics;
import nc.ui.pub.beans.UISplitPane;

/**
 * @author xuzx
 * 
 */
public class LocatableSplitPane extends UISplitPane {
	protected boolean m_canPainted = false;
	protected double m_location = -1;

	/**
	 * 
	 *
	 */
	public LocatableSplitPane() {
		super();
	}

	/**
	 * 
	 * @param newOrientation
	 * @param newContinuousLayout
	 */
	public LocatableSplitPane(int newOrientation, boolean newContinuousLayout) {
		super(newOrientation, newContinuousLayout);
	}

	/**
	 * 
	 * @param newOrientation
	 * @param newLeftComponent
	 * @param newRightComponent
	 */
	public LocatableSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent) {
		super(newOrientation, newLeftComponent, newRightComponent);
	}

	/**
	 * 
	 * @param newOrientation
	 * @param newContinuousLayout
	 * @param newLeftComponent
	 * @param newRightComponent
	 */
	public LocatableSplitPane(int newOrientation, boolean newContinuousLayout, Component newLeftComponent,
			Component newRightComponent) {
		super(newOrientation, newContinuousLayout, newLeftComponent, newRightComponent);
	}

	/**
	 * 
	 * @param iOrientation
	 */
	public LocatableSplitPane(int iOrientation) {
		super(iOrientation);
	}

	/**
	 *
	 */
	protected boolean hasLocation() {
		return (m_location != -1);
	}

	/**
	 * 
	 *
	 */
	public void cancelDividerLocation() {
		m_location = -1;
	}

	public void setCanpaint(boolean b){
		m_canPainted = b;
	}
	/**
	 * 
	 */
	public void setDividerLocation(double location) {
		if (location < 0 || location > 1) {
			throw new IllegalArgumentException("Illegal value for divider location: " + location);
		}
		m_location = location;
		if (m_canPainted) {
			super.setDividerLocation(m_location);
		}
	}
	public double getDividerLocationPos(){
		return m_location;
	}

	/**
	 * 
	 */
	public void paint(Graphics g) {
		
		if (!m_canPainted) {
			if (hasLocation()) {
				super.setDividerLocation(m_location);
				m_canPainted = true;
				doLayout();
				repaint();
			}
		}
		else{
			super.paint(g);
		}
	}

}
